package com.jdy.haoduoaiteacher.util;

import com.jdy.haoduoaiteacher.model.LeCachedPushStory;
import com.jdy.haoduoaiteacher.model.LeCachedTellStory;
import com.jdy.haoduoaiteacher.model.LeMachine;
import com.jdy.haoduoaiteacher.model.LeUser;
import com.jdy.haoduoaiteacher.parse.JsonSerializer;

/**
 * 
 * @author hufei
 * 
 */
public class LePreference extends BasePreference {

  private static LePreference instance;

  public final static String PREFERNCE_BABYRADIO_CACHE = "BABYRADIO_CACHE";
  public final static String PREFERNCE_SUITCARTOON_CACHE = "SUITCARTOON_CACHE";
  public final static String PREFERNCE_TELLSTORY_CACHE = "TELLSTORY_CACHE";
  public final static String PREFERNCE_PUSHSTORY_CACHE = "PUSHSTORY_CACHE";
  public final static String PREFERNCE_PUSHSLIDE_CACHE = "PUSHSLIDE_CACHE";
  public final static String PREFERNCE_SHARERANK_CACHE = "SHARERANK_CACHE";
  public final static String PREFERNCE_NEXT_TIMESTAMP = "LAST_TIMESTAMP";
  public final static String PREFERNCE_LAST_PUSHTIMESTAMP = "LASTPUSH_TIMESTAMP";
  public final static String PREFERNCE_LAST_BABYRADIOSTAMP = "LASTBABYRADIO_TIMESTAMP";
  public final static String PREFERNCE_LAST_SUITCARTOONTIMESTAMP = "LASTSUITCARTOON_TIMESTAMP";
  public final static String PREFERNCE_LEUSER_INFO = "PREFERNCE_LEUSER_INFO";
  public final static String PREFERNCE_LEBABY_INFO = "PREFERNCE_LEBABY_INFO";

  public static LePreference getInstance() {
    if (instance == null) {
      instance = new LePreference();
    }
    return instance;
  }

  public LeCachedTellStory getCachedTellStory() {
    checkPrefs();
    LeCachedTellStory logininfo = null;
    String json = getString(PREFERNCE_TELLSTORY_CACHE);
    if (!Tools.isEmpty(json)) {
      logininfo = JsonSerializer.getInstance().deserialize(json,
          LeCachedTellStory.class);
    }
    return logininfo;
  }

  // public void saveCachedTellStory(LeCachedTellStory cachedTellStory) {
  // checkPrefs();
  // String json = "";
  // if (cachedTellStory != null) {
  // json = JsonSerializer.getInstance().serialize(cachedTellStory);
  // }
  //
  // save(PREFERNCE_TELLSTORY_CACHE, json);
  // }

  public LeCachedPushStory getCachedPushStory() {
    checkPrefs();
    LeCachedPushStory logininfo = null;
    String json = getString(PREFERNCE_PUSHSTORY_CACHE);
    if (!Tools.isEmpty(json)) {
      logininfo = JsonSerializer.getInstance().deserialize(json,
          LeCachedPushStory.class);
    }
    return logininfo;
  }

  // public void saveCachedPushStory(LeCachedPushStory cachedTellStory) {
  // checkPrefs();
  // String json = "";
  // if (cachedTellStory != null) {
  // json = JsonSerializer.getInstance().serialize(cachedTellStory);
  // }
  //
  // save(PREFERNCE_PUSHSTORY_CACHE, json);
  // }

  public void saveLeUserInfo(LeUser lu) {
    checkPrefs();
    String json = "";
    if (lu != null) {
      json = JsonSerializer.getInstance().serialize(lu);
    }

    save(PREFERNCE_LEUSER_INFO, json);
  }

  public LeUser getLeUser() {
    checkPrefs();
    LeUser lu = null;
    String json = getString(PREFERNCE_LEUSER_INFO);
    if (!Tools.isEmpty(json)) {
      lu = JsonSerializer.getInstance().deserialize(json, LeUser.class);
    }
    return lu;
  }

  public void saveLeBabyInfo(LeMachine lm) {
    checkPrefs();
    String json = "";
    if (lm != null) {
      json = JsonSerializer.getInstance().serialize(lm);
    }

    save(PREFERNCE_LEBABY_INFO, json);
  }

  public LeMachine getLeBaby() {
    checkPrefs();
    LeMachine lm = null;
    String json = getString(PREFERNCE_LEBABY_INFO);
    if (!Tools.isEmpty(json)) {
      lm = JsonSerializer.getInstance().deserialize(json, LeMachine.class);
    }
    return lm;
  }
}
